﻿
<template>
    <div class="tab-filter-type pt20">

        <div class="oh">
            <h5 class="pull-left tr">用水时间：</h5>
            <ul class="tab-type ft14">
                <li>
                    <el-select placeholder="灌溉年度" size="mini" v-model="ggnd">
                        <el-option-group v-for="group in ggnddata"
                                         :key="group.TypeNO"
                                         :label="group.TypeNO">
                            <el-option v-for="item in group.gjdata"
                                       :key="item.LB"
                                       :label="group.TypeNO+'-'+item.LB"
                                       :value="item.KSSJ+','+item.JSSJ">
                            </el-option>
                        </el-option-group>
                    </el-select>
                    <el-date-picker v-model="qzsj" size="mini"
                                    type="daterange"
                                    value-format="yyyy-MM-dd"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期">
                    </el-date-picker>
                </li>
            </ul>
        </div>
        <div class="oh"  v-show="isshow">
            <h5 class="pull-left tr">管理站：</h5>
            <ul class="tab-type ft14">
                <li v-for="lb in lbdata"><span v-bind:class="{ 'active': lb.issel }" @click="sellb(lb)" v-text="lb.itemtext"></span></li>
            </ul>
        </div>
    </div>

</template>


<script>
    //输出得查询格式必须为{ colid: obj.cxzd, cal: obj.cal, val: va.itemtext }，colid为字段,cal为查询类型(0:等于,1:包含-逗号隔开).val为值
    module.exports = {
        props: ['pzoption'],
        data() {
            return {
                qzsj: "",
                lb: "",
                isshow: false,
                ggnddata: [],
                sdate: "",
                edate: "",
                ggnd: "",
                lbdata: [{ issel: true, itemtext: "全部" }, { issel: false, itemtext: "青化灌溉站" }, { issel: false, itemtext: "汤峪灌溉站" }, { issel: false, itemtext: "齐镇灌溉站" }, { issel: false, itemtext: "金渠灌溉站" }, { issel: false, itemtext: "安乐灌溉站" }],
            };
        },
        computed: {
            dx: function () {
                return this.isdx == "";
            }
        },
        methods: {
            getq: function () {
                this.pzoption.value = [];
                if (this.lb.itemtext != "全部") {
                    this.pzoption.value.push({ colid: "zname", cal: "0", val: this.lb.itemtext });
                }
                this.pzoption.value.push({ colid: "crdate", cal: "5", val: this.qzsj.join() });


            },
            sellb: function (lb) {
                this.lb = lb;
                _.forEach(this.lbdata, function (obj) {
                    obj.issel = false;
                })
                lb.issel = true;
                this.getq();
                this.$parent.Query();
            },
        },
        watch: {
            'qzsj': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        this.getq();
                        this.$parent.Query();
                    }
                },
                deep: true
            },
            'ggnd': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        chi.qzsj = [newV.split(",")[0], newV.split(",")[1]];
                    }
                },
                deep: true
            }

        },
        mounted: function () {
            var chi = this;
            chi.$nextTick(function () {
                var userrole = top.model.UserInfo.UserRoleCode;
                if (userrole.indexOf('1218') > -1 || userrole.indexOf('1268') > -1 || userrole.indexOf('1269') > -1) {
                    chi.isshow = true;
                }
                chi.ggnddata = JSON.parse(ComFunJS.getCookie("ggnd"));
                chi.sdate = chi.ggnddata[0].gjdata[0].KSSJ;
                chi.edate = chi.ggnddata[0].gjdata[2].JSSJ;
                chi.ggnd = chi.sdate + "," + chi.edate;
                chi.qzsj = [chi.ggnddata[0].gjdata[0].KSSJ, chi.ggnddata[0].gjdata[2].JSSJ];
            })

        }
    };
</script>